package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CooperativeMerchant;
import com.ruoyi.system.service.ICooperativeMerchantService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合作商户Controller
 * 
 * @author ruoyi
 * @date 2021-04-07
 */
@RestController
@RequestMapping("/system/cooperativemerchant")
public class CooperativeMerchantController extends BaseController
{
    @Autowired
    private ICooperativeMerchantService cooperativeMerchantService;

    /**
     * 查询合作商户列表
     */
    @PreAuthorize("@ss.hasPermi('system:cooperativemerchant:list')")
    @GetMapping("/list")
    public TableDataInfo list(CooperativeMerchant cooperativeMerchant)
    {
        List<CooperativeMerchant> list = cooperativeMerchantService.selectCooperativeMerchantList(cooperativeMerchant);
        return getDataTable(list);
    }

    /**
     * 导出合作商户列表
     */
    @PreAuthorize("@ss.hasPermi('system:cooperativemerchant:export')")
    @Log(title = "合作商户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CooperativeMerchant cooperativeMerchant)
    {
        List<CooperativeMerchant> list = cooperativeMerchantService.selectCooperativeMerchantList(cooperativeMerchant);
        ExcelUtil<CooperativeMerchant> util = new ExcelUtil<CooperativeMerchant>(CooperativeMerchant.class);
        return util.exportExcel(list, "cooperativemerchant");
    }

    /**
     * 获取合作商户详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cooperativemerchant:query')")
    @GetMapping(value = "/{merchantId}")
    public AjaxResult getInfo(@PathVariable("merchantId") String merchantId)
    {
        return AjaxResult.success(cooperativeMerchantService.selectCooperativeMerchantById(merchantId));
    }

    /**
     * 新增合作商户
     */
    @PreAuthorize("@ss.hasPermi('system:cooperativemerchant:add')")
    @Log(title = "合作商户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CooperativeMerchant cooperativeMerchant)
    {
        return toAjax(cooperativeMerchantService.insertCooperativeMerchant(cooperativeMerchant));
    }

    /**
     * 修改合作商户
     */
    @PreAuthorize("@ss.hasPermi('system:cooperativemerchant:edit')")
    @Log(title = "合作商户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CooperativeMerchant cooperativeMerchant)
    {
        return toAjax(cooperativeMerchantService.updateCooperativeMerchant(cooperativeMerchant));
    }

    /**
     * 删除合作商户
     */
    @PreAuthorize("@ss.hasPermi('system:cooperativemerchant:remove')")
    @Log(title = "合作商户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{merchantIds}")
    public AjaxResult remove(@PathVariable String[] merchantIds)
    {
        return toAjax(cooperativeMerchantService.deleteCooperativeMerchantByIds(merchantIds));
    }
}
